package com.example.infrastructure.application;

import com.example.infrastructure.domain.person.aggregate.Person;
import com.example.infrastructure.domain.person.aggregate.valueObject.PersonType;
import com.example.infrastructure.domain.person.service.PersonDomainService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * TODO
 *
 * @author lxh
 * @date 2020/11/23 下午12:22
 **/
@Service
public class PersonApplication {
    private final PersonDomainService personDomainService;

    public PersonApplication(PersonDomainService personDomainService) {
        this.personDomainService = personDomainService;
    }

    public Optional<Person> findPerson(String personId) {
        return personDomainService.findPerson(personId);
    }

    public List<Person> findPersonByOrgId(String orgId, PersonType personType) {
        if (personType == null) {
            return findPerson(Person.build().withOrg(orgId));
        }
        return findPerson(Person.build().withOrg(orgId).withType(personType));
    }

    public List<Person> findPerson(Person example) {
        return personDomainService.findPerson(example);
    }

    public Person save(Person person) {
        return personDomainService.save(person);
    }

    public Person update(Person person) {
        return personDomainService.update(person);
    }

    public void delete(String personId) {
        personDomainService.delete(personId);
    }
}
